#ifndef _EK_KPIPE_H_
#define _EK_KPIPE_H_

#define KPIPE_BUFSIZE (PAGE_SIZE - 4)

/* the access block */
struct kpipe_buf_t
{
	 physaddr_t next;
	 char buf[KPIPE_BUFSIZE];
};

/* The control block for kpipe */
struct kpipe_t
{
	 struct mutex_t lock;

	 uint16_t   rptr;
	 uint16_t   wptr;

	 physaddr_t head;
	 physaddr_t tail;

	 uint32_t pages_count;

	 struct kpipe_buf_t pbuf __attribute__ ((aligned(PAGE_SIZE)));
};

/* alloc a new kpipe(allocating the intial control block and access
 * block */
int kpipe_open(struct kpipe_t *kpipe);
/* write to a kpipe, returns the count of chars that actually
 * written */
int kpipe_write(struct kpipe_t *kpipe, const void *buf, int n);
/* read from a kpipe, returns the count of chars that actually
 * read */
int kpipe_read(struct kpipe_t *kpipe, void *buf, int n);

#define KPPUTCH_BUFSIZE 120

#include <inc/stdarg.h>

void vkpprintf(struct kpipe_t *kpipe, const char *fmt, va_list ap);
void kpprintf(struct kpipe_t *kpipe, const char *fmt, ...);

#endif /* _EK_KPIPE_H_ */
